import asyncio
from aiohttp import web
import ssl

ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_context.load_cert_chain('domain_srv.crt', 'domain_srv.key')

num = [0]

async def handle(request):
    name = request.match_info.get('name', "Anonymous")
    text = "Hello, " + name
    num[0] += 1
    print("xxxx: ", num[0], text)
    await asyncio.sleep(6)
    return web.Response(text=text)

app = web.Application()
app.add_routes([web.get('/', handle),
                web.get('/api/v1/order/submit', handle),
                web.post('/api/v1/order/submit', handle),
                web.get('/{name}', handle)])


if __name__ == '__main__':
    # web.run_app(app)
    web.run_app(app, ssl_context=ssl_context)
